// This example is part of Diogo's code snippet database.
// http://code.google.com/p/diogo-snippets
//
// The file presents a porxy example based on a two classes (an URL and a User).
// Proxy classes act as a stand-in for other another type, particularly a low-level type that is not 
// built-in to the language. They allow easier creation, manipulation (particularly assignment into), 
// and serialization of the object, and in some cases allow operations that would not be possible or
// would be inefficient if performed on the more low-level data.

#ifndef SNIPPETS_PATTERNS_PROXY
#define SNIPPETS_PATTERNS_PROXY

// Exemple of a URL Class, prividing a higher-level abstraction of a URL (simple string), allowing
// easier parsing, creation and comparison. Without a Proxy class, each application would have
// to duplicate this code, or know how to call the appropriate functions in the right sequence. 
class UrlProxy 
{
public:
	enum URLType
	{
		HTTP,
		HTTPS,
		FTP,
		Mail
	};
	
	UrlProxy (const std::string& server, const std::string& originalUrl);
	virtual ~UrlProxy() = 0; // Wee need a virtual dtor as the goals of this class is to be a base class!

  bool sameServer (const UrlProxy&) const;

  virtual UrlProxy* clone() const = 0; // implement Prototype design pattern

  virtual void openClientApp() const = 0; // start up appropriate client

protected:
   const std::string& getOriginalUrl() const { return mOriginalUrl; }

private:
   std::string mServer;
   std::string mOriginalUrl;
};

#endif // SNIPPETS_PATTERNS_PROXY